<template>
	<view class="">
		<view class="flex1 ml-30" style="align-items: center;" v-for="(item, index) in list">
			<u-checkbox-group @change="checkboxChange(item)">
				<u-checkbox v-model="item.checked" shape="circle" :name="item.user_id">
				</u-checkbox>
			</u-checkbox-group>
			<view class="mt-20" style="width: 100rpx;height: 100rpx;">
				<image class="photo" :src="'http://im.ezongguan.com/static/photo/'+item.photo"></image>
				</image>
			</view>
			<view class="ml-30">
				{{item.nickname}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checked: false,
				arr: [],
				list: [

				]
			};
		},
		onLoad(options) {
			console.log(options);
			this.grouplist_id = options.grouplist_id
		},
		onShow() {
			this.reducetest()
		},
		methods: {
			// 移除群成员成员列表
			reducetest() {
				var params = {
					_token: uni.getStorageSync('im_token'),
					_agent_id: '1',
					list_id: this.grouplist_id,
				}
				uni.request({
					url: `http://im.ezongguan.com/im/message/groupMember`,
					method: 'POST',
					data: params,
					success: (res) => {
						console.log(res.data.data)
						this.list = res.data.data
						
					},
				})
			},
			// 删除后更新列表
			reducelist() {
				var params = {
					_token: uni.getStorageSync('im_token'),
					_agent_id: '1',
					list_id: this.grouplist_id,
				}
				uni.request({
					url: `http://im.ezongguan.com/im/message/updataNoReader`,
					method: 'POST',
					data: params,
					success: (res) => {
						console.log(res.data.data)
					},
				})
			},
			// 移除群成员-按钮确认事件
			onNavigationBarButtonTap() {
				var params = {
					_token: uni.getStorageSync('im_token'),
					_agent_id: '1',
					list_id: this.grouplist_id,
					users: JSON.stringify(this.arr)
				}
				uni.request({
					url: `http://im.ezongguan.com/im/message/removeChat`,
					method: 'POST',
					data: params,
					success: (res) => {
						console.log(res.data)
						if (res.data.msg == '已移除0位成员') {
							uni.showToast({
								title: '请选择需要移除的成员',
								icon: 'none'
							})
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}

						// this.list = res.data.data
						this.reducetest()
					},
				})
			},
			checkboxChange(i) {
				if (i.checked == true) {
					this.arr.push(i.user_id)
					console.log(this.arr);
				} else {
					this.arr.splice(this.arr.findIndex(item => item === i.user_id), 1);
					console.log(this.arr);
				}



			},
		}
	};
</script>

<style lang="less" scoped>

</style>
